package com.jidolstar.astro.vo
{
	/**
	 * Degree 단위를 가지는 값을 담는 클래스
	 * @author Yongho, Ji
	 * @since 2009.03.31 
	 */ 
	public class DMS
	{
		private var isSetDegrees:Boolean;
		private var isSetDMS:Boolean;
		
		private var _degrees:Number;
		private var _degree:int;
		private var _arcminute:int;
		private var _arcseconds:Number;
		
		public function DMS( degree:int = 0, arcminute:int = 0, arcseconds:Number = 0 )
		{
			isSetDegrees = false;
			isSetDMS = true;
			this._degree = degree;
			this._arcminute = arcminute;
			this._arcseconds = arcseconds;
		}
		
		public function setDMS( degree:int, arcminute:int, arcseconds:Number ):void
		{
			isSetDegrees = false;
			isSetDMS = true;
			this._degree = degree;
			this._arcminute = arcminute;
			this._arcseconds = arcseconds;			
		}
		
		public function get degree():int
		{
			if( !isSetDMS ) degrees2DMS();
			return _degree;
		}
		
		public function get arcminute():int
		{
			if( !isSetDMS ) degrees2DMS();
			return _arcminute;
		}
		
		public function get arcseconds():Number
		{
			if( !isSetDMS ) degrees2DMS();
			return _arcseconds;
		}
		
		public function get degrees():Number
		{
			if( !isSetDegrees )
			{
				isSetDegrees = true;
				_degrees = _degree + _arcminute/60.0 + _arcseconds/3600.0;
			}
			return _degrees;
		}
		
		public function set degrees( value:Number ):void
		{
			if( isNaN( value ) ) 
			{
				throw new ArgumentError( "value is NaN" );
			} 
			isSetDegrees = true;
			isSetDMS = false;
			_degrees = value;
		}
		
		private function degrees2DMS():void
		{
			var temp:Number;
			_degree = Math.floor( _degrees );
			temp = _degrees - _degree;
			temp *= 60.0;
			_arcminute = Math.floor( temp );
			temp -= _arcminute;
			temp *= 60.0;
			_arcseconds = temp;			
		}
	}
}